#define DEBUG
#include <cstdio>
#define INF 0x7ffffff

using namespace std;

int dice[25][5]={{}, {5, 2, 5}, {2, 3, 17}, {3, 4, 15}, {1, 1, 23}, {4, 6, 9}, {2, 7, 18}, {6, 8, 3}, {1, 5, 24}, {3, 10, 13}, {2, 11, 19}, {5, 12, 7}, {1, 9, 21}, {6, 14, 1}, {2, 15, 20}, {4, 16, 11}, {1, 13, 22}, {4, 18, 12}, {3, 19, 16}, {6, 20, 4}, {5, 17, 8}, {6, 24, 2}, {5, 21, 6}, {4, 22, 10}, {3, 23, 14}}, direct[5][2]={{}, {1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int min(int a, int b) {
  return a<b ? a : b;
}

int spfa(int x1, int y1, int x2, int y2, int *num) {
  static int dis[9][9][25], que[8*8*24+1][3], debug[9][9][25][3];
  static bool book[9][9][25];

  for (int i=1; i<=8; i++) {
    for (int j=1; j<=8; j++) {
      for (int k=1; k<=24; k++) {
	dis[i][j][k]=INF;
      }
    }
  }

  dis[x1][y1][1]=num[dice[1][0]];
  book[x1][y1][1]=true;
  que[1][0]=1, que[1][1]=x1, que[1][2]=y1;
  for (int h=0, t=1; h!=t;) {
    h=h%(8*8*24)+1;
    int x=que[h][1], y=que[h][2], z=que[h][0];
    book[x][y][z]=false;
    for (int i=1; i<=4; i++) {
      int nx=x+direct[i][0], ny=y+direct[i][1], nz=dice[z][i];
      if (nx>0 && ny>0 && nx<=8 && ny<=8) {
	if (dis[nx][ny][nz]>dis[x][y][z]+num[dice[nz][0]]) {
	  debug[nx][ny][nz][0]=z, debug[nx][ny][nz][1]=x, debug[nx][ny][nz][2]=y;
	  dis[nx][ny][nz]=dis[x][y][z]+num[dice[nz][0]];
	  if (!book[nx][ny][nz]) {
	    book[nx][ny][nz]=true;
	    t=t%(8*8*24)+1;
	    que[t][1]=nx, que[t][2]=ny, que[t][0]=nz;
	  }
	}
      }
    }
  }
  
  int ans=INF;
  for (int i=1; i<=24; i++) {
    ans = min(ans, dis[x2][y2][i]);
  }
  return ans;
}

int main() {
#ifdef DEBUG
  freopen("4628.in", "r", stdin);
  freopen("4628.out", "w", stdout);
#endif

  for (int i=1; i<=24; i++) {
    dice[dice[i][1]][3]=i;
    dice[dice[i][2]][4]=i;
  }

  static int num[7];
  int x1, y1, x2, y2;
  char c;
  scanf(" %c%d ", &c, &x1);
  y1=c-'a'+1;
  scanf(" %c%d ", &c, &x2);
  y2=c-'a'+1;
  for (int i=1; i<=6; i++) {
    scanf("%d", num+i);
  }

  printf("%d", spfa(x1, y1, x2, y2, num));

  fclose(stdin);
  fclose(stdout);
  return 0;
}
